---
layout: "default"
title: "swap"
description: "Swift documentation for 'swap': Exchange the values of a and b."
keywords: "swap,func,swift,documentation"
root: "/v3.1"
---

<div class="declaration" id="func-swap-t_-inout-t_-inout-t">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-swap-t_-inout-t_-inout-t">func swap&lt;T&gt;(<wbr>_:<wbr> inout T, _: inout T)</a>
        
<div class="comment collapse" id="comment-func-swap-t_-inout-t_-inout-t"><div class="p">
    <p>Exchange the values of <code>a</code> and <code>b</code>.</p>

<p><strong>Precondition:</strong> <code>a</code> and <code>b</code> do not alias each other.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func swap&lt;T&gt;(_ a: inout T, _ b: inout T)</code>
    
    
</div></div>
</div>
